//
//  ViewController.m
//  JQTextFieldDemo
//
//  Created by James on 15/7/21.
//  Copyright (c) 2015年 JQ. All rights reserved.
//

#import "ViewController.h"
#import "JQTextField.h"

@interface ViewController()

@property NSArray *dataSource;

@end

@implementation ViewController


- (void)viewDidLoad{
    [super viewDidLoad];
    self.textField.placeholder = @"Placeholder";
    self.textField.borderColor = [UIColor colorWithWhite:0.7 alpha:1];
    self.textField.activeBorderColor = [UIColor redColor];
    self.textField.tintColor = [UIColor redColor];
    self.dataSource = @[@"Shake",@"Glow Edge"];
}

#pragma mark - CollectionView data source

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataSource.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    btn.tag = 101 + indexPath.row;
    [btn setTitle:self.dataSource[indexPath.row] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(performAnimationFor:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:btn];
    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(100, 100);
}

#pragma mark - Cell button tapped

- (void)performAnimationFor:(UIButton *)sender{
    [self.textField wrongInputWithAnimate:sender.tag - 101];
}


@end
